{include file='public/meta'}
<title>数据表列表 - 数据管理 - 木鱼内容管理系统</title>
</head>
<body>
	<div class="layui-fluid">
		<div class="layui-card">

            <div style="padding: 10px; background-color: #FAFAFA;">
              <div class="layui-row layui-col-space15">
                <div class="layui-col-md13">
                <div class="layui-card">
                    <div class="layui-card-header muyu-text">数据批量操作 &nbsp; &nbsp; &nbsp;<span class="muyu-tips-right">(注意！InnoDB引擎表不支持修复!)</span></div>
                    <div class="layui-card-body">
                        <span style="display:inline-block;">选中项：</span>
                    <div class="layui-btn-container" style="display:inline-block;">
                      <a class="layui-btn layui-btn-xs layui-btn-normal" onclick="tableAll('optimize')" href="javascript:;">优化</a>
					  <a class="layui-btn layui-btn-xs" onclick="tableAll('analyze')" href="javascript:;">分析</a>
					  <a class="layui-btn layui-btn-xs layui-btn-warm" onclick="tableAll('repair')" href="javascript:;">修复</a>
                    </div>
                    <span style="display:inline-block;">备份操作：</span>
                    <div class="layui-btn-container" style="display:inline-block;">
                    <a class="layui-btn layui-btn-xs layui-btn-danger" onclick="openback('数据库-备份','{:url('admin/Database/backuplst',['tb'=>'database'])}')" href="javascript:;">备份所有</a>
                    </div>
                    </div>
                </div>
                </div>  
            </div>    
			</div>
			<div class="layui-card-body">
			    <span>共有数据：<span style="color:red;">{$list|count}</span> 张表</span>
            <div class="layui-table-body layui-table-main">
                <table class="layui-table" id="LAY-user-front-submit">
					<thead>
						<tr>
						    <th class=" layui-table-col-special">
							    <div class="layui-table-cell laytable-cell-checkbox">
							        <input type="checkbox" id="checkAll" onclick="isCheck()">
							    </div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>数据表名</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>数据引擎</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>数据大小</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>数据字符集</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>数据说明</span></div>
							</th>
							<th>
								<div class="layui-table-cell" align="center"><span>操作</span></div>
							</th>
						</tr>
					</thead>
					<tbody>
					    {foreach $list as $val}
						<tr align="center">
						    <td class="layui-table-col-special">
								<input type="checkbox" name="fav" value="{$val.name}">
							</td>
							<td>{$val.name}</td>
							<td>{$val.engine}</td>
							<td>{:format_size($val.data_length+$val.index_length)}</td>
							<td>{$val.collation}</td>
							<td>{$val.comment}</td>
							<td align="center" data-off="true" class="layui-table-col-special">
								<div class="layui-table-cell">
								    <a class="layui-btn layui-btn-xs layui-btn-normal" onclick="optimize('{$val.name}')" href="javascript:;">优化</a>
								    <a class="layui-btn layui-btn-xs" onclick="analyze('{$val.name}')" href="javascript:;">分析</a>
								    <a class="layui-btn layui-btn-xs layui-btn-warm" onclick="repair('{$val.name}')" href="javascript:;">修复</a>
								    <a class="layui-btn layui-btn-xs layui-btn-danger" onclick="openback('备份-{$val.name}','{:url('admin/Database/backuplst',['tb'=>$val.name])}')" href="javascript:;">备份</a>
								</div>
							</td>
						</tr>
						{/foreach}
					</tbody>
				</table>
            </div>

		</div>
	</div>


	<!-- 低部区域 -->
	{include file='public/footer'}
	<script>
		 // 全选 页面调用
            function isCheck(){
                var IsCheck= document.getElementById("checkAll");
                if(IsCheck.checked==false){
                    var groupC= document.getElementsByName("fav");
                    for(var i=0;i<groupC.length;i++){
                        groupC[i].checked=false;
                    }
                }
                if (IsCheck.checked==true) {
                    var groupC= document.getElementsByName("fav");
                    for(var i=0;i<groupC.length;i++){
                        groupC[i].checked=true;
                    }
                }
            }
	
	
	//数据表优化
	function optimize(tablename){
	    $.post("{:url('admin/Database/optimize')}",{tablename:tablename},function(res){
	        
	        if(res.code == 1){
	           layer.msg(res.msg,{time:2000},function(){
	              location.reload(); 
	           })
	        }else{
	            layer.msg(res.msg,{time:2000});
	        }
	    },'json');
	}
	
	//数据表修复
	function repair(tablename){
	    $.post("{:url('admin/Database/repair')}",{tablename:tablename},function(res){
	        if(res.code == 1){
	           layer.msg(res.msg,{time:2000},function(){
	              location.reload(); 
	           })
	        }else{
	            layer.msg(res.msg,{time:2000});
	        }
	    },'json');
	}
	//数据表分析
	function analyze(tablename){
	    $.post("{:url('admin/Database/analyze')}",{tablename:tablename},function(res){
	        if(res.code == 1){
	           layer.msg(res.msg,{time:2000},function(){
	              location.reload(); 
	           })
	        }else{
	            layer.msg(res.msg,{time:2000});
	        }
	    },'json');
	}
	
	//数据的批量修复 分析 优化操作
	function tableAll(method){
	    var name=$("tbody input:checkbox");
    	var tablename=[];
    	for(i=0;i<name.length;i++){
    		if($(name[i]).is(":checked")){
    			tablename += $(name[i]).val()+',';
    		}
    	}
    	if(tablename != ""){
    	tablename = tablename.split(",");
    	tablename = tablename.filter(function(s){
    	    return s && s.trim();
    	});
    	tablename = tablename.join(",");
    	$.post("{:url('admin/Database/"+method+"')}",{tablename:tablename},function(res){
	         if(res.code == 1){
	           layer.msg(res.msg,{time:2000},function(){
	              location.reload(); 
	           })
	        }else{
	            layer.msg(res.msg,{time:2000});
	        }
	       },'json');
    	}else{
    	   layer.msg('当前未选择任何信息!',{icon:2,time:2000}); 
    	}
	}
    //openback
    function openback(title,content){
        layer.open({
        type: 2,
        title: title,
        shadeClose: true,
        shade: 0.8,
        area: ['70%', '70%'],
        content: content 
        });
    }

	</script>
</body>
</html>